#' @export
make_descriptive_tables <- function() {

box::use(
    ./helpers/theme_helpers[conjoint_reshape, plexi, format_si, percent],
    dplyr[...],
    data.table[setDT],
    here[here],
    tibble[add_column],
    vtable[st],
    qpcR,
    xtable[xtable],
    usethis[ui_done, ui_todo, ui_info, ui_path]
)


ui_todo("Creating descriptives.")
ui_info("Figures will be in {ui_path('figs/')}, tabs in {ui_path('tabs/')}. Data in {ui_path('data/')}.")
ui_info("Input data is:")
ui_info("{ui_path('data/arms_conjoint.RDS')} - conjoint data")

df_clean <- readRDS(here("data/arms_conjoint.RDS"))


des1 <- df_clean %>% 
  filter(hCountry == "Germany") %>% 
  st(., vars = c("Education", "Age", "Gender"), out = "return", digits = 3) %>% 
  add_column(Target = c(NA, 0.195,
                        0.545,
                        0.259,
                        NA,
                        0.104,
                        0.176,
                        0.170,
                        0.200,
                        0.207,
                        0.142,
                        NA,
                        0.498,
                        0.502,
                        NA
                        )) 
 
des1$Target <- percent(des1$Target) 
setDT(des1)
des1 <- des1[Target == "NA%", Target := NA]
                       

des2 <- df_clean %>%
  filter(hCountry == "France") %>% 
  st(., vars = c("Education", "Age", "Gender"), out = "return", digits = 3)  %>% 
  add_column(Target = c(NA, 0.234,
                        0.429,
                        0.337,
                        NA,
                        0.117,
                        0.168,
                        0.179,
                        0.193,
                        0.183,
                        0.161,
                        NA,
                        0.488,
                        0.512,
                        NA
  )) 

des2$Target <- percent(des2$Target) 
setDT(des2)
des2 <- des2[Target == "NA%", Target := NA]

des2 <- select(des2, -c("Variable"))

des_comb <- qpcR:::cbind.na(des1, des2)

print(xtable(des_comb, align = "llrrrrrr"), include.rownames=FALSE, file= here("tabs/table_a_1.tex"))


r1 <- df_clean %>% 
  filter(hCountry == "Germany") %>% 
  st(., vars = c("region_de"), out = "return", digits = 3) %>% 
  add_column(Target = c(NA, 0.133,
                        0.158,
                        0.044,
                        0.030,
                        0.008,
                        0.022,
                        0.076,
                        0.019,
                        0.096,
                        0.216,
                        0.049,
                        0.012,
                        0.049,
                        0.026,
                        0.035,
                        0.026)) 

r1$Target <- percent(r1$Target) 
setDT(r1)
r1 <- r1[Target == "NA%", Target := NA]


r2 <- df_clean %>% 
  filter(hCountry == "France") %>% 
  st(., vars = c("region_fr"), out = "return", digits = 3) %>% 
  add_column(Target = c(NA, 0.124,
                        0.043,
                        0.051,
                        0.039,
                        0.005,
                        0.085,
                        0.092,
                        0.189,
                        0.051,
                        0.092,
                        0.091,
                        0.059,
                        0.078
  )) 


r2$Target <- percent(r2$Target) 
setDT(r2)
r2 <- r2[Target == "NA%", Target := NA]


r_comb <- qpcR:::cbind.na(r1, r2)

print(xtable(r_comb, align = "llrrrlrrr"), include.rownames=FALSE, , file= here("tabs/table_a_2.tex"))


add1 <- df_clean %>% 
  filter(hCountry == "Germany") %>% 
  st(., vars = c("Household_Size", "Household_Income", "Job_situation", "Econ_self", "Econ_country",
                 "Pol_Interest", "lr", "party_choice_de"), out = "return", summ = c('notNA(x)','mean(x)','sd(x)')) 

add2 <- df_clean %>% 
  filter(hCountry == "France") %>% 
  st(., vars = c("Household_Size", "Household_Income", "Job_situation", "Econ_self", "Econ_country", 
                 "Pol_Interest", "lr", "party_choice_fr"), out = "return", summ = c('notNA(x)','mean(x)','sd(x)')) 

add_comb <- qpcR:::cbind.na(add1, add2)

print(xtable(add_comb, align = "llrrrlrrr"), include.rownames=FALSE, file= here("tabs/table_a_3.tex"))

ui_done("Done creating descriptive tables.")

}